package com.atguigu.day13.work;

public class Wife extends Thread {
    private Account account;

    public Wife(Account account) {
        this.account = account;
    }

    @Override
    public void run() {
        while (true){
            synchronized (Thread.class){
                double money= Math.random()*10000;
                while (money>account.getBalance()){
                    System.out.println("本次妻子想取:"+money+"但余额不足");
                    try {
                        Thread.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("妻子取钱,目前状态:"+account);
                System.out.println("妻子本次取钱:"+money);
                account.setBalance(account.getBalance()-money);
                System.out.println("妻子取完钱:"+account);
                System.out.println();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
